const express = require('express');
const userRoutes = require('./routes/userRoutes');
const chatRoutes = require('./routes/chatRoutes');
const sequelize = require('./config/database'); // 引入 Sequelize 实例

const app = express();
app.use(express.json()); // for parsing application/json

// Connect to the database and sync models
sequelize.sync().then(() => {
  console.log('Database connected and models synced');
}).catch((error) => {
  console.error('Unable to connect to the database:', error);
});

// Use the user routes
app.use('/users', userRoutes);
app.use('/chat', chatRoutes)

module.exports = app;
